<!DOCTYPE html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>chat room</title>

<script type="text/javascript" src="http://img.txdnet.cn/js/?f=jq.js,jq.cookie-min.js,ut-min.js"></script>

<script> 

    var url = 'ChatRoomServlet';  

    function connect(){ 

        $.ajax({ 

            data:'t='+ut.r(),

            url : url, 

            type : 'get', 

            timeout : 0, 

            dataType:'text',

            success : function(r){ 

               $("#content").append('<div>' + r + '</div>'); 

            }, 

            error : function(e){ 

                $("#content").append('<div>'+e.toString()+'</div>'); 

                setTimeout(function(){ connect();}, 3000); 

            }, 

            complete : function(){ 

                     connect();

            } 

        });

    };

    function sendmsg(){ 

        $.ajax({ 

            data :  $('#msgfrm').serialize(), 

            type : 'get', 

            url : url ,

            timeout : 3000, 

            dataType:'text'

        }) 

    };

</script>

</head>

<body>

    <div id="content"></div> 

    <form action="" method="get" id="msgfrm"> 

      昵称:<input type="text" name="user" id="user" value="tonydon" />

      发言：<input type="text" name="msg" id="msg" value="mmm" /> 

      <input type="button" value="Send" onclick="sendmsg();"/> 

    </form> 


     <script>

           ut.wait(function(){ connect();}, 5000);

     </script>

</body>

</html>
